package com.wolf.util;

import com.wolf.pojo.Wl_commodity_inventory_record;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;

public class execl {

    public static void text(List<Wl_commodity_inventory_record> list){
    //工作簿
    HSSFWorkbook hwd = new HSSFWorkbook();

    //选项卡
    HSSFSheet hr = hwd.createSheet("库存预警");

    HSSFRow hfr = hr.createRow(0);

    hfr.createCell(0).setCellValue("名称");

    hfr.createCell(1).setCellValue("属性");

    hfr.createCell(2).setCellValue("数量");

    hfr.createCell(3).setCellValue("库存状态");

    hfr.createCell(4).setCellValue("条形码");

    hfr.createCell(5).setCellValue("过期时间");

    hfr.createCell(6).setCellValue("状态");

    hfr.createCell(7).setCellValue("序号");

    for (int i = 0; i < list.size(); i++) {
        HSSFRow newHF = hr.createRow(i+1);
        newHF.createCell(0).setCellValue(list.get(i).getWl_commodity().getCommodityname());
        newHF.createCell(1).setCellValue(list.get(i).getProperty());
        newHF.createCell(2).setCellValue(list.get(i).getOperatequantity());
        newHF.createCell(3).setCellValue(list.get(i).getWl_commodity_inventory().getStatus());
        newHF.createCell(4).setCellValue(list.get(i).getWl_commodity_inventory().getBarcode());

        if(list.get(i).getWl_commodity_inventory().getExpiretime()!=null){
            newHF.createCell(5).setCellValue(list.get(i).getWl_commodity_inventory().getExpiretime());

        }

        newHF.createCell(6).setCellValue(list.get(i).getStatus());
        newHF.createCell(7).setCellValue(list.get(i).getId());
    }

    FileOutputStream out;
    try {
        out = new FileOutputStream("F://execl.xls");
        hwd.write(out);

        try {
            out.close();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

//        JOptionPane.showMessageDialog(null, "ok");

    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
}

